package 字串;

/**
 * @author tmh
 * @date 2024/8/29 23:00
 * @description
 */
public class T560和为K的子数组 {
    //采用暴力解法-双循环
    public int subarraySum(int[] nums, int k) {
        int len = nums.length;
        int count = 0;
        //外层循环-遍历数组
        //内层循环-对数组进行我们的逻辑操作（粗鄙理解）
        for (int i = 0; i < len; i++) {
            int sum = 0;
            for (int j = i; j < len; j++) {
                sum += nums[j];
                if (sum == k) {
                    count++;
                }
            }
        }
        return count;
    }
}
